﻿<!--#include file="../inc/common.asp" -->
<%
    if not userRightObj.canManage then
        message("您没有设置权限")
    end if
    call OpenDB
%>
<HTML><HEAD><TITLE><%=blogObj.blogTitle%>—控制面板—链接管理</TITLE>
<link rel="stylesheet" href="<%=cssFile%>" type="text/css" />

<style type="text/css">
td{
    font-size:10pt;
}
</style>

<script language=javascript>
    function editLink(){
    }
    function deleteLink(){
    }
</script>

</head>
<body bgcolor="#c1c1c1" leftmargin="0" topmargin="0" style="font-size:10pt">
<div style="width:760px;height:100%;">

    <div style="float:left;width: 160px; padding-top:20px">
    <!--#include file="menu.asp" -->
    </div>

    <div style="background:#ffffff; width:580px; height:100%;float:left;padding:20px 10px 10px 10px">
<%
    dim group_id, group_name, group_desc, display_seq
    group_id = trim(request("group_id"))
    if group_id="" then
%>
    <p>请选择要编辑的链接组：</p>
<%
        sql = " select group_id, group_name, group_desc, display_seq from blog_link_group where blog_id=" & blogObj.blogId & " order by display_seq"
        rs.open sql, conn, 1, 1
        while not rs.bof and not rs.eof 
          group_id=rs("group_id")
%>
    <p>&nbsp;&nbsp;<a href="links.asp?blog_id=<%=blogObj.blogId%>&group_id=<%=group_id%>"><%=rs("group_name")%></a></p>
<%
          rs.moveNext()
        wend
        rs.close()
%>
    <p>或者<a href="links.asp?blog_id=<%=blogObj.blogId%>&group_id=-1">新增链接组</a></p>
<%  
    else
        group_id = clng(group_id)
        dim actionType
        actionType = request("actionType")
        sql = " select group_id, blog_id, group_name, group_desc, display_seq from blog_link_group where blog_id=" & blogObj.blogId & " and group_id=" & group_id
        rs.open sql, conn, 1, 3
        if rs.bof or rs.eof then
        else
            group_name = rs("group_name")            
            group_desc = rs("group_desc")
            display_seq = rs("display_seq")
        end if
        if actionType=" 删除 " then
            rs.delete()
            
            blogObj.loadLinkGroupsFromDB()
            blogObj.cache()

            call closeDB()
            
            response.redirect("links.asp?blog_id="&blogObj.blogId)
            response.end
        elseif actionType=" 保存修改 " then
            if rs.bof or rs.eof then
                rs.addNew()
                rs("blog_id")=blogObj.blogId
            end if
            group_name = filterHTML(request("group_name"))            
            group_desc = filterHTML(request("group_desc"))
            display_seq = filterHTML(request("display_seq"))
            if trim(display_seq)="" then
                display_seq = 1
            end if
            rs("group_name") = group_name            
            if group_desc<>"" then
                rs("group_desc") = group_desc
            end if    
            rs("display_seq") = display_seq
            rs.update()
            group_id = rs("group_id")
            
            blogObj.loadLinkGroupsFromDB()
            blogObj.cache()            
            response.write("<font color=red><b>保存成功！</b></font><br> ")
        end if
        rs.close()    
%>
    <form name=form1 action=links.asp method=post>
        <input type=hidden name=blog_id value="<%=blogObj.blogId%>">
        <input type=hidden name=group_id value="<%=group_id%>">
        <p>链接组名称：<input type=text name=group_name size=60 value="<%=group_name%>" </p>
        <p>链接组描述：<textarea name=group_desc cols=59 rows=3 ><%=group_desc%></textarea> </p>
        <p>显示顺序：<input type=text name=display_seq size=3 value="<%=display_seq%>"></p>
        <p align=center><input type=submit name=actionType value=" 保存修改 ">
<%
      if group_id<>"" and group_id<>"-1" then 
%>
        <input type=submit name=actionType value=" 删除 " onclick="return confirm('注意：删除操作会同时删除该链接组下的所有链接！\n\n确定要删除吗？')">
<% 
      end if
%>
<%
        if group_id<>"" and group_id<>"-1" then
            dim link_id, link_name, link_url, link_img, link_desc, link_display_seq
            sql = " select link_id, blog_id,link_group, link_name, link_url, link_desc, link_img, display_seq from blog_links where blog_Id=" & blogObj.blogId & " and link_group=" & group_id & " order by display_seq "
            rs.open sql,conn,1,3
            link_id = clng(request("link_id"))
            if actionType="保存链接" then    
                link_name = filterHTML(request("link_name"))
                link_url = filterHTML(request("link_url"))
                link_img = filterHTML(request("link_img"))
                link_desc = filterHTML(request("link_desc"))
                link_display_seq = filterHTML(request("link_display_seq"))

                
                'response.write link_url
                'response.end
                
                if link_id<>"" then
                    rs.find "link_id=" & link_id
                    if rs.bof or rs.eof then
                        link_id=""
                    end if    
                end if
                
                if link_id="" then
                    rs.addNew()
                    rs("blog_id")=blogObj.blogId
                    rs("link_group")=group_id
                end if
                rs("link_url") = link_url
                if link_name="" then
                    link_name = link_url
                end if    
                rs("link_name") = link_name
                if link_img<>"" then
                    rs("link_img") = link_img
                end if    
                if link_desc="" then
                    link_desc = link_name
                end if
                rs("link_desc") = link_desc
                if link_display_seq="" then
                    link_display_seq = 1
                end if    
                rs("display_seq")=link_display_seq
                rs.update()
                link_id = rs("link_id")
                
                blogObj.loadLinkGroupsFromDB()
                blogObj.cache()                  
            elseif actionType="deleteLink" then
                rs.find "link_id=" & link_id
                if not rs.bof and not rs.eof then
                    rs.delete()
                    link_id = ""
                end if    

                blogObj.loadLinkGroupsFromDB()
                blogObj.cache()                  
            end if    

%>
        <input type=button  value=" 返回 " onclick="document.location.href='links.asp?blog_id=<%=blogObj.blogId%>'">
        </p>
        <p><b>链接列表：</b><br>
        <table border=0 cellspacing=4 cellpadding=4>
<%
            if rs.bof or rs.eof then
            else
                rs.moveFirst()
                do until rs.bof or rs.eof
%>
            <tr>
              <td>
                <%=rs("display_seq")%>
              </td>
              <td><a href="<%=rs("link_url")%>" title='<%=rs("link_desc")%>' target=_blank>
<%
                    if rs("link_img")<>"" then
                        response.write "<img border=0 src=" & rs("link_img") &" >"
                    else
                        response.write rs("link_name")
                    end if    
%>
                  </a>
              </td>
              <td>
                <a href="links.asp?blog_id=<%=blogObj.blogId%>&group_id=<%=group_id%>&link_id=<%=rs("link_id")%>&actionType=editLink">编辑</a>
              </td>
              <td>
                <a href="links.asp?blog_id=<%=blogObj.blogId%>&group_id=<%=group_id%>&link_id=<%=rs("link_id")%>&actionType=deleteLink">删除</a>
              </td>
            </tr>  
<%                    
                    rs.moveNext()
                loop
                link_name=""
                link_url=""
                link_img=""
                link_desc=""    
                link_display_seq=""
                if actionType = "editLink" then       
                    rs.moveFirst()
                    rs.find "link_id=" & link_id
                    if not rs.bof and not rs.eof then
                        link_name = rs("link_name")
                        link_url = rs("link_url")
                        link_img = rs("link_img")
                        link_desc = rs("link_desc")
                        link_display_seq = rs("display_seq")
                    else    
                        link_id=""
                    end if 
                else
                    link_id=""
                end if    
            end if
            rs.close()
            if link_url="" then
                link_url="http://"
            end if    
%>
        </table>
        </p>       
        <p><b>编辑链接：</b><br>
        <input type=hidden name=link_id value="<%=link_id%>">
        链接名称：<input type=text name=link_name  value="<%=link_name%>" size=15 maxlength=20><br>
        链接地址：<input type=text name=link_url  value="<%=link_url%>" size=30><br>
        链接图片：<input type=text name=link_img  value="<%=link_img%>" size=30><br>
        链接描述：<input type=text name=link_desc  value="<%=link_desc%>" size=30><br>
        排列顺序：<input type=text name=link_display_seq size=3 value="<%=link_display_seq%>"><br>
        
        <input type=submit name=actionType  value="保存链接" onclick="javascript: if (form1.link_url.value=='') { alert('请输入链接地址'); return false;} else return true;">
        </p>

<%        end if    

%>        
        
    </form>
<%
    end if    
%>    
    </div>

<div>
</body>    
</html>    
<!--#include file="../inc/end.asp" -->
